package com.github.md11235.ideaproofofwork.cfiletracker

import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.ui.components.JBList
import com.intellij.ui.content.ContentFactory
import javax.swing.DefaultListModel
import javax.swing.JPanel
import java.time.LocalTime
import java.time.format.DateTimeFormatter

object CFileTrackerUI {
    val model = DefaultListModel<String>()
    val list = JBList(model)

    fun addEvent(event: String) {
        val timestamp = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"))
        model.addElement("[$timestamp] $event")
    }
}

class CFileTrackerToolWindowFactory : ToolWindowFactory, DumbAware {
    override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
        val panel = JPanel()
        panel.layout = java.awt.BorderLayout()
        panel.add(CFileTrackerUI.list, java.awt.BorderLayout.CENTER)

        val content = ContentFactory.getInstance().createContent(panel, "", false)
        toolWindow.contentManager.addContent(content)
    }
}
